package middleware

import (
	"github.com/gin-gonic/gin"
	"golang.org/x/time/rate"
	"time"
)

func RateLimiter() gin.HandlerFunc {
	limiter := rate.NewLimiter(rate.Every(time.Minute), 10) // 每分钟10次
	return func(c *gin.Context) {
		if !limiter.Allow() {
			c.AbortWithStatusJSON(429, gin.H{"error": "请求过于频繁"})
		}
	}
}
